﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Configuration;

using MobileBroadbandLoggingMonitorUI.Interfaces;
using MobileBroadbandLoggingMonitorUI.Implementations;
using MobileBroadbandLoggingMonitorUI.UI.Interfaces;

namespace MobileBroadbandLoggingMonitorUI
{
    public partial class MainForm : Form, IMainFormView
    {



        public MainForm()
        {
            InitializeComponent();
        }

        private void _btnStartLogging_Click(object sender, EventArgs e)
        {
            if (StartLoggingClicked != null)
            {
                StartLoggingClicked(sender, e);
            }
        }

        private void _btnStopLogging_Click(object sender, EventArgs e)
        {
            if (StopLoggingClicked != null)
            {
                StopLoggingClicked(sender, e);
            }
        }

        private void _lnkSolution_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (SolutionClicked != null)
            {
                SolutionClicked(sender, e);
            }
        }

        private void _lnkBlog_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (BlogClicked != null)
            {
                BlogClicked(sender, e);
            }
        }

        private void _lnkFeedback_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (SuggestionsClicked != null)
            {
                SuggestionsClicked(sender, e);
            }
        }


        #region IMainFormView Members

        public event EventHandler StartLoggingClicked;

        public event EventHandler StopLoggingClicked;

        public event EventHandler SolutionClicked;

        public event EventHandler BlogClicked;

        public event EventHandler SuggestionsClicked;

        public event EventHandler ShareAnonymousInformationClicked;

        public event EventHandler Closing;

        public void SetChangePerMinute(string value)
        {
            this.Invoke(new SetTextDelegate(SetChangePerMinuteThread), value);
        }
        private void SetChangePerMinuteThread(string value)
        {
            _lblChangesMinute.Text = value;
        }


        public void SetChangePerHour(string value)
        {
            this.Invoke(new SetTextDelegate(SetChangePerHourThread), value);
       }
        private void SetChangePerHourThread(string value)
        {
            _lblChangesHour.Text = value;
        }

        public void SetChangePerWorkday(string value)
        {
            this.Invoke(new SetTextDelegate(SetChangePerWorkdayThread), value);
        }
        public void SetChangePerWorkdayThread(string value)
        {
            _lblChangesWorkday.Text = value;
        }

        public void SetFoundSoftware(string value)
        {
            _lblFoundSoftware.Text = value;
        }

        public void SetStartLoggingButtonEnabledState(bool enabled)
        {
            _btnStartLogging.Enabled = enabled;
        }

        public void SetStopLoggingButtonEnabledState(bool enabled)
        {
            _btnStopLogging.Enabled = enabled;
        }

        public void SetLoggingText(string value)
        {
            this.Invoke(new SetTextDelegate(SetLoggingTextThreadSafe), value);
        }

        private delegate void SetTextDelegate(string value);

        private void SetLoggingTextThreadSafe(string value)
        {
            _txbLoggingOutput.Text = value;
            
        }

        public void SetSolutionLinkVisible(bool visible)
        {
            _lnkSolution.Visible = visible;
        }

        public new void Invoke(Delegate theDelegate)
        {
            this.Invoke(theDelegate);
        }

        public void FocusStartButton()
        {
            _btnStartLogging.Focus();
        }

        public void FocusStopButton()
        {
            _btnStopLogging.Focus();
        }

        #endregion

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (Closing != null)
            {
                Closing(sender, e);
            }

        }

        private void MainForm_Load(object sender, EventArgs e)
        {
        }

        private void _txbLoggingOutput_Enter(object sender, EventArgs e)
        {
            _lnkBlog.Focus();
        }


        public bool GetShareAnonymousInformationState()
        {
            return _chkShareInformationAnonymously.Checked;
        }

        private void _chkShareInformationAnonymously_Click(object sender, EventArgs e)
        {
            if (ShareAnonymousInformationClicked != null)
            {
                ShareAnonymousInformationClicked(sender, e);
            }
        }

        public void SetShareAnonymousInformationState(bool isChecked)
        {
            _chkShareInformationAnonymously.Checked = isChecked;
        }
    }

}
